home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18397 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  56 lines

  1. Path: ix.netcom.com!netnews
  2. From: Robert Kleemann <goose@ix.netcom.con>
  3. Newsgroups: comp.lang.c++
  4. Subject: Correct Ansi C++ behavior?
  5. Date: Fri, 19 Apr 1996 09:54:58 -0700
  6. Organization: Netcom
  7. Message-ID: <3177C562.7578@ix.netcom.con>
  8. NNTP-Posting-Host: sea-wa11-20.ix.netcom.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-NETCOM-Date: Fri Apr 19  9:54:45 AM PDT 1996
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. The following code compiles cleanly with MS VC v4.0 but I believe the last 
  16. line should result in an error.  Does anyone know for certain whether this is 
  17. a bug or correct C++ behavior?  I don't have any other compilers to test it 
  18. on.
  19.  
  20. thanx!
  21. Robert
  22.  
  23. class Bar;
  24.  
  25. class Foo
  26. {
  27. public:
  28.     Foo();
  29.     Foo(const Foo& p);
  30. private:
  31.     // only Bar member functions and friends can
  32.     // create a Foo object from a Bar object
  33.     Foo(const Bar& p);
  34. };
  35.  
  36. class Bar
  37. {
  38. public:
  39.     Bar();
  40.     Bar(const Bar& p);
  41.     // any function can create a Bar object
  42.     // from a Foo object
  43.     Bar(const Foo& p);
  44. private:
  45. };
  46.  
  47. void main()
  48. {
  49.     Foo f;
  50.     Bar b;
  51.     Bar b2(f); // legal
  52.     b = Bar(f); // legal
  53.     //Foo f2(b); // should be illegal and is
  54.     f = Foo(b); // I believe this should also be illegal but it isn't
  55. }
  56.